<template>
  <el-dialog
    title="关于我们"
    :visible.sync="dialogVisible"
    width="500px"
    @close="onClose"
    :modal-append-to-body="false"
    :append-to-body="false"
    center>
    <div class="about-content">
      <div class="company-info">
        <h3>{{ companyName }}</h3>
        <p>{{ companyDescription }}</p>
      </div>
      
      <!-- 软件更新部分 -->
      <div class="update-section">
        <div class="version-info">
          <el-button 
            type="primary" 
            size="small"
            :loading="checking"
            @click="checkUpdate">
            检查更新
          </el-button>
          <div class="version-text">当前版本: {{ currentVersion }}</div>
        </div>

        <!-- 更新进度 -->
        <div v-if="downloading" class="update-progress">
          <el-progress 
            :percentage="downloadProgress"
            :format="progressFormat">
          </el-progress>
        </div>
      </div>

      <div class="qr-code">
        <img :src="qrCodeImageUrl" alt="QR Code">
        <p>扫码关注我们</p>
      </div>
      
      <div class="copyright">
        <p>Copyright © {{ copyrightYear }} {{ companyName }}</p>
      </div>
    </div>

    <!-- 更新提示对话框 -->
    <el-dialog
      title="发现新版本"
      :visible.sync="showUpdateDialog"
      width="400px"
      append-to-body>
      <div class="update-info">
        <p>最新版本: {{ updateInfo.version }}</p>
        <p>更新说明:</p>
        <div class="update-notes">{{ updateInfo.releaseNotes }}</div>
      </div>
      <span slot="footer">
        <el-button @click="showUpdateDialog = false">暂不更新</el-button>
        <el-button type="primary" @click="doUpdate">立即更新</el-button>
      </span>
    </el-dialog>
  </el-dialog>
</template>

<script>

export default {
  name: 'AboutUs',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    companyName: {
      type: String,
      required: true
    },
    companyDescription: {
      type: String,
      required: true
    },
    qrCodeImageUrl: {
      type: String,
      required: true
    },
    copyrightYear: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      dialogVisible: false,
      currentVersion: process.env.VUE_APP_VERSION,
      checking: false,
      downloading: false,
      downloadProgress: 0,
      showUpdateDialog: false,
      updateInfo: {}
    }
  },
  watch: {
    visible: {
      immediate: true,
      handler(val) {
        this.dialogVisible = val;
      }
    },
    dialogVisible(val) {
      if (val !== this.visible) {
        this.$emit('update:visible', val);
      }
    }
  },
  methods: {
    onClose() {
      this.$emit('update:visible', false)
    },
    // 检查更新
    checkUpdate() {
    },
    // 开始更新
    doUpdate() {
      this.showUpdateDialog = false
      this.downloading = true
    },
    // 进度条格式化
    progressFormat(percentage) {
      return percentage === 100 ? '下载完成' : `${percentage}%`
    }
  },
  mounted() {
  
  }
}
</script>

<style lang="scss" scoped>
.about-content {
  text-align: center;
  padding: 20px;

  .company-info {
    margin-bottom: 30px;
    
    h3 {
      font-size: 20px;
      margin-bottom: 15px;
    }
    
    p {
      color: #666;
      line-height: 1.6;
    }
  }

  .update-section {
    margin-bottom: 30px;
    
    .version-info {
      display: flex;
      flex-direction: column;
      align-items: center;
      
      .version-text {
        margin-top: 8px;
        color: #666;
        font-size: 13px;
      }
    }

    .update-progress {
      margin-top: 15px;
    }
  }

  .qr-code {
    margin-bottom: 30px;
    
    img {
      width: 150px;
      height: 150px;
      margin-bottom: 10px;
    }
    
    p {
      color: #666;
    }
  }

  .copyright {
    color: #999;
    font-size: 12px;
  }
}

.update-info {
  .update-notes {
    margin-top: 10px;
    padding: 10px;
    background: #f5f7fa;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
  }
}

// 套对话框样式调整
::v-deep .el-dialog__wrapper {
  .el-dialog {
    margin-top: 15vh !important;
  }
}
</style>